home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d902.lha / Less / Source / source.lha / ttyin.c < prev    next >
C/C++ Source or Header  |  1993-01-21  |  1KB  |  70 lines

  1. /*
  2.  * Routines dealing with getting input from the keyboard (i.e. from the user).
  3.  */
  4.  
  5. #include "less.h"
  6.  
  7. /*
  8.  * The boolean "reading" is set true or false according to whether
  9.  * we are currently reading from the keyboard.
  10.  * This information is used by the signal handling stuff in signal.c.
  11.  * {{ There are probably some race conditions here
  12.  *    involving the variable "reading". }}
  13.  */
  14. public int reading;
  15.  
  16. #ifndef AMIGA
  17. static int tty;
  18. #endif
  19.  
  20.  
  21. /*
  22.  * Open keyboard for input.
  23.  * (Just use file descriptor 2.)
  24.  */
  25. #ifdef __STDC__
  26. void open_getchr (void)
  27. #else
  28.         public void
  29. open_getchr()
  30. #endif
  31. {
  32. #ifdef AMIGA
  33.         ttopen();
  34. #else
  35.         tty = 2;
  36. #endif
  37. }
  38.  
  39. /*
  40.  * Get a character from the keyboard.
  41.  */
  42. #ifdef __STDC__
  43. int getchr (void)
  44. #else
  45.         public int
  46. getchr()
  47. #endif
  48. {
  49.         char c;
  50.         int result;
  51.  
  52.         reading = 1;
  53.         do
  54.         {
  55.                 flush();
  56. #ifdef AMIGA
  57.                 c = ttgetc();
  58.                 result = 1;
  59. #else
  60.                 result = read(tty, &c, 1);
  61. #endif
  62.         } while (result != 1);
  63.         reading = 0;
  64. #ifdef EIGHTBIT
  65.         return (int) c;
  66. #else
  67.         return (c & 0177);
  68. #endif
  69. }
  70.